package com.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.naming.NamingException;

public class BookingDAO extends EmployeesBaseDAO {
	public static List<Booking> findReserveDay(String name, int year,int month) throws NamingException{
		ResultSet rs = null;
		Connection conn = null;
		try{
			conn = getConnection();
			Statement statement = conn.createStatement();
//			String query = "Select day(start_date) as day , hour(start_date) as Start_hour, hour(end_date) as End_hour from booking where name='" + name + "' and year(Start_date)='" + year + "' and month(Start_date)='" + month + "'"; 
			String query = "Select distinct day(start_date) as day from booking where name='" + name + "' and year(Start_date)='" + year + "' and month(Start_date)='" + month + "'";
			rs = statement.executeQuery(query);
			List<Booking> Bookings = new ArrayList<Booking>();			
			while(rs.next()){
				Booking b = new Booking();
				b.setReserveDay(Integer.valueOf(rs.getString("day")));
//				b.setReserveStartHour(Integer.valueOf(rs.getString("Start_hour")));
//				b.setReserveEndHour(Integer.valueOf(rs.getString("End_hour")));				
				Bookings.add(b);				
			}
			conn.commit();
			rs.close();
			conn.close();
			return Bookings;				
			
		}
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static List<BookingDetail> GetBookingDetail(String name,int year,int month,int TotalDayInMonth,int FirstDayWeek) throws NamingException{	
		List<BookingDetail> Details = new ArrayList<BookingDetail>();
		BookingDetail d = new BookingDetail();
		d.setName(name);
		d.setYear(year);
		d.setMonth(month);
		d.setFirstDayWeek(FirstDayWeek);
		d.setTotalDayInMonth(TotalDayInMonth);
		Details.add(d);
		return Details;		
	}
}

